package com.zhiyou100.pra;

/**
 * 学生操作类
 */
public class StudentOpe {

    /**
     * 按照成绩从高到低的顺序输出姓名、学号和成绩信息
     */
    public void sortStu(Student[] stus){
        //根据学生成绩排序输出   .......  第二节
        Student student = null;
        //冒泡排序,按成绩倒叙
        for(int i = 0;i< stus.length-1;i++) {
            for (int j = 0; j < stus.length - 1 - i; j++) {
                if (stus[j].getScore() < stus[j + 1].getScore()) {
                    student = stus[j];
                    stus[j] = stus[j + 1];
                    stus[j + 1] = student;
                }
            }
        }
        //按顺序输出打印学生信息
        for(int i = 0;i<stus.length;i++){
            System.out.print("学生姓名是：" + stus[i].getName() + "\t");
            System.out.print("学生学号是："+ stus[i].getNum() + "\t");
            System.out.print("学生成绩是：" + stus[i].getScore() + "\t");
            System.out.println();
        }
    }

    static Student[] students = new Student[4];
    //利用静态代码块对students进行数据初始化
    static {
        students[0] = new Student("张三","20187895",56.9);
        students[1] = new Student("李四","20187893",66.9);
        students[2] = new Student("王五","20187894",54.9);
        students[3] = new Student("赵六","20187892",76.9);
    }

    public static void main(String[] args) {
        StudentOpe ope = new StudentOpe();
        ope.sortStu(students);
    }

}
